package main;

import java.util.ArrayList;
import java.util.Timer;

public class Simulator implements Runnable{

	public float timer = 0;
	static int FIFO = 1;
	static int CLOCK = 2;
	static int LRUn = 3;
	static int NFU = 4;
	static int WSClock = 5;
	static public ArrayList<Page> pageList = Algorithms.populatePageArray();
	private Thread t;
	private String threadName;
	
	public Simulator(String name){
	       threadName = name;
	       System.out.println("Creating processes" +  threadName );
	   }
	
	public Page usePage(Page page){
		
		page.time = timer + 1;
		page.r = 1;
		
		return page;
	}
	/*
	public static void main(String[] args) throws Exception {
		
		
		ArrayList<Page> pageList = Algorithms.populatePageArray();
		
		
		for (int i = 0; i < 100; i++) {
			
			int random = (int)(Math.random() * 2);
			
			Page tempPage = pageList.get(i);
			tempPage.r = 1;
			
			
			if(i>7){
				
				
				
				if(random == 1){
				
					Clock.add(tempPage);
					System.out.println("added " + tempPage.id);
				
				} else {
				
					System.out.println("skipping");
				
				}	
				
				
			}else{
				
				Clock.add(tempPage);
				
			}
			
		}
		
	}
	*/
	public void start (){
		
			for (int i = 0; i < 100; i++) {
			
				int random = (int)(Math.random() * 2);
			
				Page tempPage = pageList.get(i);
				tempPage.r = 1;
			
			
				if(i>7){
				
				
				
					if(random == 1){
				
						Clock.add(tempPage);
						System.out.println("added " + tempPage.id);
				
					} else {
				
						System.out.println("skipping");
					
				}	
				
				
				}else{
				
					Clock.add(tempPage);
				
			}
		}
	}
	
	public void run() {
		System.out.println("Running " +  threadName );
	    
		try {
	         for(int i = 4; i > 0; i--) {
	            System.out.println("Thread: " + threadName + ", " + i);
	            
	            Thread.sleep(5);
	         }
	     } catch (InterruptedException e) {
	         System.out.println("Thread " +  threadName + " interrupted.");
	     }
	     System.out.println("Thread " +  threadName + " exiting.");
	   }
		
	}
	
